package com.datang.petstore.controller.web;


/*
 * @auther 顶风少年
 * @mail dfsn19970313@foxmail.com
 * @date 2019-10-29 10:07
 * @notify 登录相关api
 * @version 1.0
 */

import com.datang.petstore.entity.ManageUser;
import com.datang.petstore.resultpage.Result;
import com.datang.petstore.resultpage.ResultCode;
import com.datang.petstore.service.ManageUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
public class WebLoginController {

    @Autowired
    private ManageUserService manageUserService;


    /*
     * @author 顶风少年
     * @date 2019/11/15 6:25
     * @mail dfsn199703132038@foxmail.com
     * @throws
     * @param
     * @result java.util.List<com.datang.petstore.model.SummaryUserSexResponse>
     * @notify 校验用户密码
     * version 1.0
     */
    @PostMapping("register/check")
    public Result check(@RequestBody ManageUser manageUser, HttpSession session) {
        List<ManageUser> manageUser1 = manageUserService.getManageUser(manageUser);
        if (manageUser1.size() != 1) {
            return Result.err(ResultCode.error515);
        } else {
            session.setAttribute("username", manageUser1.get(0));
            return Result.ok(manageUser1.get(0));
        }
    }

}
